home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue49 / Factory / Animals.pas next >
Encoding:
Pascal/Delphi Source File  |  1999-06-16  |  1.8 KB  |  89 lines

  1. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.   TechInsite Pty. Ltd. 
  3.   PO Box 429, Abbotsford, Melbourne. 3067 Australia
  4.   Phone: +61 3 9419 6456
  5.   Fax:   +61 3 9419 1682
  6.   Web:   www.techinsite.com.au
  7.   EMail: peter_hinrichsen@techinsite.com.au
  8.  
  9.   Created: 01/06/1999
  10.  
  11.   Notes: Family of TAnimal descendants for factory demo
  12.  
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  14. unit Animals;
  15.  
  16. interface
  17. uses
  18.   Classes
  19.   ;
  20.  
  21. type
  22.  
  23.   TAnimal = class( TObject )
  24.   public
  25.     Procedure Talk ; virtual ; abstract ;
  26.   end ;
  27.  
  28.   TDog = class( TAnimal )
  29.   public
  30.     Procedure Talk ; override ;
  31.   end ;
  32.  
  33.   TCat = class( TAnimal )
  34.   public
  35.     Procedure Talk ; override ;
  36.   end ;
  37.  
  38.   TBird = class( TAnimal )
  39.   public
  40.     Procedure Talk ; override ;
  41.   end ;
  42.  
  43. implementation
  44. uses
  45.    Dialogs
  46.   ,FactoryConcreteAnimal
  47.   ,Constants
  48.   ;
  49.  
  50. { TDog }
  51.  
  52. procedure TDog.Talk;
  53. begin
  54.   showMessage( 'Woof' ) ;
  55. end;
  56.  
  57. { TCat }
  58.  
  59. procedure TCat.Talk;
  60. begin
  61.   ShowMessage( 'Meow' ) ;
  62. end;
  63.  
  64. { TBird }
  65.  
  66. procedure TBird.Talk;
  67. begin
  68.   ShowMessage( 'Tweet' ) ;
  69. end;
  70.  
  71. initialization
  72.  
  73.   // Register the classes with the animal factory. Note the third parameter
  74.   // is true which so these objects will be cached once they are created.
  75.   gFactoryConcreteAnimal.RegisterClass( cgStrAnimalDog,
  76.                                         TDog,
  77.                                         True ) ;
  78.  
  79.   gFactoryConcreteAnimal.RegisterClass( cgStrAnimalCat,
  80.                                         TCat,
  81.                                         True ) ;
  82.  
  83.   gFactoryConcreteAnimal.RegisterClass( cgStrAnimalBird,
  84.                                         TBird,
  85.                                         True ) ;
  86.  
  87.  
  88. end.
  89.